package com.originskyseed.platform.count.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.originskyseed.platform.core.aspect.annotation.RequiredParams;
import com.originskyseed.platform.core.base.BaseController;
import com.originskyseed.platform.core.base.BaseLocaleResource;
import com.originskyseed.platform.core.base.BasePage;
import com.originskyseed.platform.core.base.BaseResponseBody;
import com.originskyseed.platform.core.common.code.CommonResponseCode;
import com.originskyseed.platform.count.i18n.CountResponseMsg;
import com.originskyseed.platform.count.model.UserBonus;
import com.originskyseed.platform.count.service.IUserBonusService;
import com.originskyseed.platform.count.vo.request.UserBonusRequestVO;

/**
 * 用户奖金信息表Controller类（OSI_USER_BONUS）
 * 
 * @author Tangwanghui
 */
@Controller
@RequestMapping("/userBonus")
@BaseLocaleResource(localeFileName = "i18n_count")
public class UserBonusController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(UserBonusController.class);

	@DubboReference
	private IUserBonusService userBonusService;

	/**
	 * 分页查询
	 * 
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/userBonusList.json", method = RequestMethod.POST)
	@RequiredParams(names = { "pageNo", "pageSize" })
	public BaseResponseBody<BasePage<UserBonus>> userBonusList(HttpServletRequest request) {
		BaseResponseBody<BasePage<UserBonus>> result = null;
		try {
			// 请求对象
			UserBonusRequestVO requestVO = this.getParameterBean(UserBonusRequestVO.class);

			// 分页查询
			BasePage<UserBonus> page = new BasePage<UserBonus>(requestVO.getPageNo(), requestVO.getPageSize());
			page = this.userBonusService.selectListByPage(requestVO.toMap(), page);
			result = new BaseResponseBody<BasePage<UserBonus>>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.SUCCESS.getMsg()), page);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<BasePage<UserBonus>>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 保存信息
	 * 
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/userBonusSave.json", method = RequestMethod.POST)
	public BaseResponseBody<UserBonus> userBonusSave(HttpServletRequest request) {
		BaseResponseBody<UserBonus> result = null;
		try {
			// 请求对象
			UserBonus userBonus = this.getParameterBean(UserBonus.class);

			if (StringUtils.isNotBlank(userBonus.getId())) {
				this.userBonusService.updateByPrimaryKeySelective(userBonus);
			} else {
				this.userBonusService.insertSelective(userBonus);
			}
			result = new BaseResponseBody<UserBonus>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SAVE_SUCCESS.getMsg()), userBonus);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<UserBonus>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SAVE_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

}